//
//  DockVw.m
//  QQZone
//
//  Created by 树清吴 on 2017/10/15.
//  Copyright © 2017年 shuQingWu. All rights reserved.
//

#import "DockVw.h"
#import "DDTabbarView.h"
#import "DDToolView.h"
#import "DDIconView.h"

@interface DockVw ()

@property (nonatomic, strong) DDTabbarView *tabView;
@property (nonatomic, strong) DDToolView *toolView;
@property (nonatomic, strong) DDIconView *iconView;


@end

@implementation DockVw


- (instancetype)initWithFrame:(CGRect)frame
{

    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = DDGrayColor;
        [self addSubview:self.tabView];
        [self addSubview:self.toolView];
        [self addSubview:self.iconView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    NSInteger ratio = 3;
    
    // 设置tab
    CGFloat width = self.width;
    CGFloat x = 0;
    CGFloat height = 0;
    if (DDPortrait) {
        // 竖屏
         height = width * ratio;
        
    }else{
        height = width / ratio;
    }
    CGFloat y = self.height - height;
    self.tabView.frame = CGRectMake(x, y, width, height);
    
    // 设置toolView
    CGFloat tabbarH = 0;
    if (DDPortrait) {
        tabbarH = self.width * 6;
    }else{
        tabbarH = self.width / ratio * 6;
    }
    CGFloat tabbarY = self.height - height - tabbarH;
    self.toolView.frame = CGRectMake(x, tabbarY, width, tabbarH);
    
    // 设置iconView
    CGFloat iconW = self.width * 0.8;
    CGFloat iconH = 0;
    if (DDPortrait) {
        iconH = iconW;
    }else{
        iconH = iconW + 30;
    }
    CGFloat iconX = (self.width - iconW) / 2;
    CGFloat iconY = (tabbarY - iconH) / 2;
    NSLog(@"%f", tabbarY);
    self.iconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
    
    
//    NSLog(@"%f", 237.0 / 255.0);
//    [UIColor colorWithWhite: alpha:]
    
}

#pragma mark -- 懒加载
- (DDTabbarView *)tabView{
    if (_tabView == nil) {
        _tabView = [DDTabbarView new];
    }
    return _tabView;
}

- (DDToolView *)toolView{
    if (_toolView == nil) {
        _toolView = [DDToolView new];
    }
    return _toolView;
}

- (DDIconView *)iconView{
    if(_iconView == nil ){
        _iconView = [DDIconView new];
    }
    return _iconView;
}

@end
